<template>
  <div class="form_1">
    <el-form :model="form" status-icon :rules="rules" ref="ruleForm" label-width="50px">
      <el-form-item label="账号" prop="account">
        <el-input v-model="form.account"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" v-model="form.password"></el-input>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import {ref, watch} from "vue";
import { getCurrentInstance} from 'vue'

const currentInstance = getCurrentInstance()
let name = 'Form1'
let form = ref({
  account: '',
  password: ''
})
let ruleForm = ref(null)
let validateAccount = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('请输入账号'));
  }
  callback()
}
let validatePass = (rule, value, callback) => {
  if (value === '') {
    callback(new Error('请输入密码'));
  }
  callback()
}
let rules = ref({
  account: [
    {validator: validateAccount, trigger: 'blur'}
  ],
  password: [
    {validator: validatePass, trigger: 'blur'}
  ],
})
let validateCurrent = () => {
  return new Promise((resolve, reject) => {
    ruleForm.value.validate((valid) => {
      if (valid) resolve()
    })
  })
}


let show = () => {
}

defineExpose({
  form,
  name,
  show,
  validateCurrent
})

console.log(currentInstance)

</script>

<style scoped>
.form_1 {
  width: 450px;
}
</style>